import javax.swing.tree.TreeNode;
import java.util.LinkedList;
import java.util.Queue;
//101 - 对称二叉树
class Solution {
    public boolean isSymmetric(TreeNode root) {
        return cheak(root,root);
    }
    public boolean cheak(TreeNode a, TreeNode b){
        if(a == null && b == null){
            return true;
        }
        if(a == null || b == null){
            return false;
        }
        return a.val == b.val
                && cheak(a.left, b.right)
                && cheak(a.right, b.left);
    }
}
class Solution {
    public boolean isSymmetric(TreeNode root) {
        Queue<TreeNode> node = new LinkedList<>();
        node.offer(root);
        node.offer(root);
        while(!node.isEmpty()){
            TreeNode a = node.poll();
            TreeNode b = node.poll();
            if(a == null && b == null){
                continue;
            }
            if(a == null || b == null){
                return false;
            }
            if(a.val != b.val){
                return false;
            }
            node.offer(a.right);
            node.offer(b.left);

            node.offer(a.left);
            node.offer(b.right);
        }
        return true;
    }
}
//100 - 相同的树
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        Queue<TreeNode> node = new LinkedList<>();
        node.offer(p);
        node.offer(q);
        while(!node.isEmpty()){
            p = node.poll();
            q = node.poll();
            if(p == null && q == null){
                continue;
            }
            if(p == null || q == null){
                return false;
            }
            if(p.val != q.val){
                return false;
            }
            node.offer(p.left);
            node.offer(q.left);

            node.offer(p.right);
            node.offer(q.right);
        }
        return true;
    }
}
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null && q == null){
            return true;
        }else if(p == null || q == null){
            return false;
        }
        return p.val == q.val &&
                isSameTree(p.right,q.right) && isSameTree(p.left,q.left);
    }
}
public class Leetcode {
}
